
package com.newtouch.common;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;



/**
 * Map 工具类
 * @author lm
 */
public class MapUtil {
	
	/**
	 * 将Map中的数组取第一个值代替数组
	 * Struts 2.0.6版本做页面映射时使用
	 * @param m
	 */
	public static void strutsActionMap(Map<String, Object> m){
		if(m==null) return;
		Set<String> st = m.keySet();
		Iterator<String> iter = st.iterator();
		while(iter.hasNext()){
			String mk = iter.next();
			Object obj = m.get(mk);
			if (obj instanceof String[]) {
				Object[] mv = (Object[]) obj;				
				m.put(mk, mv.length > 0 ? mv[0] : null);
			}
		}
	}
	/*	
	@SuppressWarnings({ "unused", "unchecked" })
	private void test(){
		Map map = new HashMap();  
		map.put("1", "a");  
		map.put('2', 'b');  
		map.put('3', 'c');  
		// 遍历
		Iterator iter = map.entrySet().iterator();
		while (iter.hasNext()) {
		    Map.Entry entry = (Map.Entry) iter.next();
		    Object key = entry.getKey();
		    Object val = entry.getValue();
		} 
		System.out.println(map);  
		// 输出所有的值  
		System.out.println(map.keySet());  
		// 输出所有的键  
		System.out.println(map.values());  
		// 将map的值转化为List  
		List list = new ArrayList(map.values());  
		System.out.println(list);  
		// 将map的值转化为Set  
		Set set = new HashSet(map.values());  
		System.out.println(set);  
	}
	*/
	/**
	 * @param args
	 */
	/*
	public static void main(String[] args) {
		//Map<String, Object> map = new HashMap<String, Object>();
		MapBean map = new MapBean();
		String[] s = {"11"};
		String[] s2 = {"11","22"};
		String[] s3 = {""};
		map.put("aa", "aaaaaaaa");
		map.put("bb", s);
		map.put("cc", "cccccccc");
		map.put("dd", s2);
		map.put("ee", s3);
		strutsActionMap(map);

	}
*/
}
